package br.com.bco.web.component;

import org.apache.wicket.markup.html.form.Button;

import br.com.bco.negocio.exception.NegocioException;

public abstract class ButtonValidateble extends Button {

	public ButtonValidateble(String id) {
		super(id);
	}

	@Override
	public final void onSubmit() {
		try {
			onSubmitForm();
		} catch (NegocioException e) {
			addMensagens(e);
		}
	}

	private void addMensagens(NegocioException e) {
		for (String mensagem : e.getMensagens()) {
			error(mensagem);
		}
	}

	protected abstract void onSubmitForm();

}
